package com.bottle.client;

import com.bottle.mode.RequestMessage;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author: chenyuncong
 * @Date: 2020/5/9 14:24
 */
@Slf4j
@Component
public class CharClientImpl implements CharClient {

    @Value("${bottle.server.url}")
    private String url;

    @Override
    public String send(RequestMessage request) {
        // JSON 字符串
        try {
//            private String encrUserId;//发送人加密id
//            private String encrBridgeId;//接收桥梁解密id
//            private String content;//内容
//            private Long sendTime;//发送时间

            Map<String, String> parameter = Maps.newHashMap();
            parameter.put("encrUserId",request.getEncrUserId());
            parameter.put("encrBridgeId",request.getEncrBridgeId());
            parameter.put("content",request.getContent());
            parameter.put("sendTime",System.currentTimeMillis()+"");

            String json = OkHttpRequestUtils.doPost(url+"receive", parameter);
            return json;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "";
    }

    @Override
    public void receive(String json) {
        log.info(json);
    }
}
